package com.sbkj.shunbaowallet.mvp_lvxingxing;

import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;

import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;

/**
 * Created by lvxingxing on 2017/12/12.
 *
 * @author lvxingxing
 */

public class MyApp extends Application {
    private static final String TAG = "MyApp";
    private RefWatcher refWatcher;
    private static Context mContext;
    protected static int mainThreadId;

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        //解决64K问题
        MultiDex.install(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = getApplicationContext();
        mainThreadId = android.os.Process.myTid();
        refWatcher = setupLeakCanary();
    }

    private RefWatcher setupLeakCanary() {
        if (LeakCanary.isInAnalyzerProcess(this)) {
            return RefWatcher.DISABLED;
        }
        return LeakCanary.install(this);
    }

    public static RefWatcher getRefWatcher(Context context) {
        MyApp leakApplication = (MyApp) context.getApplicationContext();
        return leakApplication.refWatcher;
    }

    public static Context getContext(){
        return mContext;
    }

    public static int getMainThreadId(){
        return mainThreadId;
    }
}
